/**
 * 
 */
package com.wzl.qs;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * @author Wu Wei
 * 
 */
public class Tabs extends TabActivity implements TabHost.OnTabChangeListener {

	// private static final String[] TABS = { "TabOne", "TabTwo" };
	private TabHost mTabHost;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.tabs);

		mTabHost = getTabHost();
		mTabHost.setOnTabChangedListener(this);
		setupTab1();
		setupTab2();
		setupTab3();

		setDefaultTab(0);

	}

	private void setupTab1() {
		// Force the class since overriding tab entries doesn't work
		Intent intent = new Intent("com.wzl.qs.QuitSmoking");
		intent.setClass(this, QuitSmoking.class);

		mTabHost
				.addTab(mTabHost.newTabSpec("notelist").setIndicator("Encourages",
						getResources().getDrawable(R.drawable.light))
						.setContent(intent));
	}

	private void setupTab2() {
		// Force the class since overriding tab entries doesn't work
		Intent intent = new Intent("com.wzl.qs.AddNote");
		intent.setClass(this, AddNote.class);

		mTabHost
				.addTab(mTabHost.newTabSpec("addnote").setIndicator("Add",
						getResources().getDrawable(R.drawable.add1))
						.setContent(intent));
	}

	private void setupTab3() {
		// Force the class since overriding tab entries doesn't work
		Intent intent = new Intent("com.wzl.qs.mFavorite");
		intent.setClass(this, mFavorite.class);

		mTabHost.addTab(mTabHost.newTabSpec("addnote").setIndicator(
				"Favorites", getResources().getDrawable(R.drawable.tab3))
				.setContent(intent));
	}

	@Override
	public void onTabChanged(String tabId) {
		// Because we're using Activities as our tab children, we trigger
		// onWindowFocusChanged() to let them know when they're active. This may
		// seem to duplicate the purpose of onResume(), but it's needed because
		// onResume() can't reliably check if a keyguard is active.
		Activity activity = getLocalActivityManager().getActivity(tabId);
		if (activity != null) {
			activity.onWindowFocusChanged(true);
		}
		
//		if(activity.getClass()==QuitSmoking.class)
	}

	// public static class MyTabIndicator extends LinearLayout {
	// public MyTabIndicator(Context context, String label) {
	// super(context);
	//
	// View tab = ViewInflate.from(context).inflate(
	// R.layout.tab_indicator, this, null);
	//
	// TextView tv = (TextView) tab.findViewById(R.id.tab_label);
	// tv.setText(label);
	// }
	// }

}
